home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GX Libraries / OvalLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  2.3 KB  |  82 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        OvalLibrary.c
  4.  
  5.     Contains:    graphics libraries - oval routines
  6.     
  7.     Written by:    Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  8.     
  9.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  10.  
  11.     Change History (most recent first):
  12.  
  13.          <1>      1/9/95    JD        First checked in.
  14. */
  15.  
  16. #include "GraphicsLibraries.h"
  17.  
  18. #define FRACROOT2less1  444758426
  19.  
  20. /*
  21.   * ovalPath must be 18 fixed numbers. Set the gxPath
  22.   * to the oval described in theOval.
  23.   */
  24. static void OvalPath(Fixed ovalPath[], const gxRectangle *r)
  25. {
  26.     register Fixed *pointWalker;
  27.     register Fixed cx, cy, h, v;
  28.  
  29.     cx = (r->left + r->right)/2;
  30.     cy = (r->top + r->bottom)/2;
  31.     h = FractMultiply(FRACROOT2less1, (r->right - r->left)/2);
  32.     v = FractMultiply(FRACROOT2less1, (r->bottom - r->top)/2);
  33.     pointWalker = ovalPath;                     /* start at the beginning       */
  34.     *pointWalker++ = 8;                         /* eight points             */
  35.     *pointWalker++ = 0xFF000000;                /* all points off gxCurve     */
  36. /*
  37.   * Start on the left edge, go up and around
  38.   */
  39.     *pointWalker++ = r->left;       *pointWalker++ = cy - v;
  40.     *pointWalker++ = cx - h;        *pointWalker++ = r->top;
  41.     *pointWalker++ = cx + h;        *pointWalker++ = r->top;
  42.     *pointWalker++ = r->right;  *pointWalker++ = cy - v;
  43.  
  44.     *pointWalker++ = r->right;  *pointWalker++ = cy + v;
  45.     *pointWalker++ = cx + h;        *pointWalker++ = r->bottom;
  46.     *pointWalker++ = cx - h;        *pointWalker++ = r->bottom;
  47.     *pointWalker++ = r->left;       *pointWalker++ = cy + v;
  48. }
  49.  
  50.  
  51. gxShape NewOval(const gxRectangle *ovalData)
  52. {
  53.     Fixed ovalPath[18];                              /* 1 vector count, 1 control bit long, 8 points */
  54.  
  55.     NilParamReturnNil(ovalData);
  56.     OvalPath(ovalPath, ovalData);
  57.     return NewPath((gxPath *) ovalPath);
  58. }
  59.  
  60. void SetOval(gxShape s, const gxRectangle *ovalData)
  61. {
  62.     Fixed ovalPath[18];
  63.  
  64.     NilShapeReturn(s);
  65.     NilParamReturn(ovalData);
  66.  
  67.     OvalPath(ovalPath, ovalData);
  68.     SetPath(s, 0, (gxPath *)ovalPath);
  69. }
  70.  
  71.  
  72. void DrawOval(const gxRectangle *ovalData, gxShapeFill geom)
  73. {
  74.     register gxShape ovalShape;
  75.     
  76.     NilParamReturn(ovalData);
  77.     ovalShape = NewOval(ovalData);
  78.     GXSetShapeFill(ovalShape, geom);
  79.     GXDrawShape(ovalShape);
  80.     GXDisposeShape(ovalShape);
  81. }
  82.